package engine.logic
{
	import engine.newUi.PackUI;
	import engine.ui.lite.BaseUI;
	
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.utils.getQualifiedClassName;
	import flash.utils.getTimer;
	
	import newx.StageInfo;
	import newx.com.config.StaticIni;

	/**
	 * 数据采集逻辑类，
	 * @author wanghb
	 * 
	 */	
	public class LogSendLogic
	{
		
		//用来按钮点击次数计数的对象
		private var _btnClickObj		:Object
		private var _uiOpenObj			:Object
		private var _checkUIObj		:Object;
		private var _showUIName		:String;
		private var _stageClickName	:String;
		private var _actTime			:int;
		private static var _self:LogSendLogic;
		public function LogSendLogic()
		{
			_btnClickObj	=	{};
			_uiOpenObj	=	{};
			_checkUIObj	=	StaticIni.getIniObj("LogSendUI") as Object;
		}
		public static function getInstance():LogSendLogic
		{
			if(_self == null)
			{
				_self	=	new LogSendLogic();
			}
			return _self;
		}
		/**
		 * 按钮点击次数 
		 * @param btnID
		 * 
		 */		
		public function btnClickNumSend(actID:int):void
		{
			if(_btnClickObj[String(actID)] == null)
			{
				_btnClickObj[String(actID)]	=	1;
			}
			else
			{
				_btnClickObj[String(actID)] ++;
			}
			ActSee.PostLoginBtn(actID,_btnClickObj[String(actID)]);
		}
		/**
		 * 打开界面的次数 
		 */		
		public function openUINum(targetUI:BaseUI):void
		{
//			return;
			_showUIName	=	(getQualifiedClassName(targetUI) as String).split("::")[1];
			if(_checkUIObj[_showUIName] != null)
			{
				if(_uiOpenObj[_showUIName] != null)
				{
					_uiOpenObj[_showUIName] ++;
				}
				else
				{
					_uiOpenObj[_showUIName]	=	1;
				}
				if(!StageInfo.stage.hasEventListener(MouseEvent.CLICK))
				{
					StageInfo.stage.addEventListener(MouseEvent.MOUSE_DOWN,stageClickHandle);
				}
				_actTime	=	getTimer();
			}
		}
		/**
		 * 舞台侦听事件
		 * @param e
		 * 
		 */		
		private function stageClickHandle(e:MouseEvent):void
		{
			StageInfo.stage.removeEventListener(MouseEvent.MOUSE_DOWN,stageClickHandle);
			var target:DisplayObject	=	e.target as DisplayObject;
			if(target != null)
			{
				_stageClickName	=	getQualifiedClassName(target) as String;
//				trace("_____________________________________" + _stageClickName + "************" + target);
				ActSee.PostLogicUI(_checkUIObj[_showUIName],_uiOpenObj[_showUIName],_stageClickName,getTimer() - _actTime);
			}
		}
		
	}
}